package dk.mirasola.systemtraining.biddingsession.client.util;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.RootPanel;

public abstract class BiddingSessionAsyncCallback<T> implements AsyncCallback<T> {
    protected static class FailurePopup extends PopupPanel {
        public FailurePopup(Throwable failure) {
            super(true);
            setWidth("200px");
            int popupLeft = (RootPanel.get().getOffsetWidth() / 2) - 100;
            setPopupPosition(popupLeft, 200);
            this.setWidget(new Label(failure.getLocalizedMessage()));
        }
    }

    public void onFailure(Throwable throwable) {
        new FailurePopup(throwable).show();
    }
}
